package com.ruoyi.project.system.word.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.word.domain.Word;
import com.ruoyi.project.system.word.service.IWordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 系统文档管理 信息操作处理
 *
 * @author lxs
 * @date 2018-10-17
 */
@Controller
@RequestMapping("/system/word")
public class WordController extends BaseController {
    private String prefix = "system/word";

    @Autowired
    private IWordService wordService;

    @RequiresPermissions("beautyflower:word:view")
    @GetMapping()
    public String word() {
        return prefix + "/word";
    }

    /**
     * 查询系统文档管理列表
     */
    @RequiresPermissions("beautyflower:word:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Word word) {
        startPage();
        List<Word> list = wordService.selectWordList(word);
        return getDataTable(list);
    }

    /**
     * 新增系统文档管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存系统文档管理
     */
    @RequiresPermissions("beautyflower:word:add")
    @Log(title = "系统文档管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Word word) {
        return toAjax(wordService.insertWord(word));
    }

    /**
     * 修改系统文档管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Word word = wordService.selectWordById(id);
        mmap.put("word", word);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统文档管理
     */
    @RequiresPermissions("beautyflower:word:edit")
    @Log(title = "系统文档管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Word word) {
        return toAjax(wordService.updateWord(word));
    }

    /**
     * 删除系统文档管理
     */
    @RequiresPermissions("beautyflower:word:remove")
    @Log(title = "系统文档管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(wordService.deleteWordByIds(ids));
    }

    /**
     * 发布
     *
     * @param id 需要发布的数据ID
     * @return 结果
     */
    @RequiresPermissions("beautyflower:word:release")
    @Log(title = "系统文档管理", businessType = BusinessType.UPDATE)
    @PostMapping("/release")
    @ResponseBody
    public AjaxResult release(String id) {
        return toAjax(wordService.release(id));
    }

    /**
     * 取消发布
     *
     * @param id 需要发布的数据ID
     * @return 结果
     */
    @RequiresPermissions("beautyflower:word:cancelRelease")
    @Log(title = "系统文档管理", businessType = BusinessType.UPDATE)
    @PostMapping("/cancelRelease")
    @ResponseBody
    public AjaxResult cancelRelease(String id) {
        return toAjax(wordService.cancelRelease(id));
    }
}
